package com.game77.guessTheWords2.sprite;

import android.graphics.Typeface;

import com.game77.guessTheWords2.core.GameSystem;
import com.wiyun.engine.nodes.Label;
import com.wiyun.engine.nodes.Node;
import com.wiyun.engine.nodes.Sprite;
import com.wiyun.engine.types.WYColor3B;

public class TipBlock extends Node {

	Sprite background;
	Label verticalTip;
	Label horizontalTip;

	public TipBlock() {
		background = Sprite.make(GameSystem.tex_tip_back);
		background.setPosition(0, 0);
		this.addChild(background);

		verticalTip = Label.make("竖:", GameSystem.TipFontSize, Typeface.BOLD);
		verticalTip.setColor(WYColor3B.make(0, 180, 0));
		verticalTip.setPosition(20f, -34.25f);
		verticalTip.setLineWidth(400);
		this.addChild(verticalTip);

		horizontalTip = Label.make("横:", GameSystem.TipFontSize, Typeface.BOLD);
		horizontalTip.setColor(WYColor3B.make(255, 0, 0));
		horizontalTip.setPosition(20f, 34.25f);
		horizontalTip.setLineWidth(400);
		this.addChild(horizontalTip);

		// init
		verticalTip.setVisible(false);
		horizontalTip.setVisible(false);
	}

	public void setDefault() {
		verticalTip.setVisible(false);
		horizontalTip.setVisible(false);
	}

	public void setTip(String hTip, String vTip) {
		verticalTip.setFontSize(GameSystem.TipFontSize);
		verticalTip.setVisible(true);
		horizontalTip.setFontSize(GameSystem.TipFontSize);
		horizontalTip.setVisible(true);

		// 动态设置字体
		if (hTip.length() > 34) {
			horizontalTip.setFontSize(GameSystem.TipFontSize - 3);
		} else if (hTip.length() < 13) {
			horizontalTip.setFontSize(GameSystem.TipFontSize + 3);
		}
		if (vTip.length() > 34) {
			verticalTip.setFontSize(GameSystem.TipFontSize - 3);
		} else if (vTip.length() < 13) {
			verticalTip.setFontSize(GameSystem.TipFontSize + 3);
		}

		if (!hTip.equals("")) {
			horizontalTip.setText(hTip);
		} else {
			horizontalTip.setText("");
		}
		if (!vTip.equals("")) {
			verticalTip.setText(vTip);
		} else {
			verticalTip.setText("");
		}
	}
}
